<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        section{
            width: 300px;
            height: 550px;
            border: 1px solid red;
            /* 怪异盒模型 */
            box-sizing: border-box;
            padding: 20px;
            margin: 25px auto;
            /* 弹性盒 */
            display: flex;
            /* 改主轴方向 */
            flex-direction: column;
            /* 侧轴对齐方式 */
            align-items: center;
        }
        section img{
            width: 265px;
            /* 等比例缩放图片 */
            height: auto;
        }
        section p:nth-of-type(1){
            font-size: 12px;
            color: #6b6969;
            margin: 10px 0 12px;
        }
        section h3{
            font-size: 16px;
            line-height: 16px;
            font-weight: 900;
            margin-bottom: 26px;
        }
        section>div{
            font-size: 12px;
            color: #808080;
            display: inline-flex;
            text-align: center;
            line-height: 28px;
            margin-bottom: 24px;
        }
        section>div div{
            display: flex;
            width: 116px;
            margin-left: 10px;
        }
        section>div div span{
            border: 1px solid #e6e6e6;
        }
        section>div div span:nth-child(1),span:nth-child(3){
            width: 28px;
            height: 28px;
            /* 禁止文本选中属性，注意兼容 */
            user-select:none;
        }
        section>div div span:nth-child(2){
            flex: 1;
        }
        section p:nth-of-type(2){
            font-size: 16px;
            color: #000;
        }
    </style>
</head>
<body>
    <section>
        <img src="./img/2.jpg" alt="">
        <p>纪梵希 小羊皮口红304</p>
        <h3>￥ <span id='price'>340</span></h3>
        <div>
            数量
            <div>
                <span id='sub'>-</span>
                <span id='number'>0</span>
                <span id='add'>+</span>
            </div>
        </div>
        <p>总价￥：<span id='total'>0</span></p>
    </section>

    <script>
        //取值
        var pri = price.innerHTML*1;
        var num = number.innerHTML*1;
        var tp = Number(total.innerHTML);

        //点击事件
        sub.onclick = function(){
            //不能小于0
            if(num > 0){
                num--;
                number.innerHTML = num;
                tp = pri*num;
                total.innerHTML = tp;
            }
        }
        add.onclick = function(){
            num++;
            number.innerHTML = num;
            tp = pri*num;
            total.innerHTML = tp;
        }

    </script>
</body>
</html>